<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>课程审核</title>
    <script src="/jquery/jquery-3.2.1.min.js"></script>
    <script src="/layui/layui.js"></script>
    <link rel="stylesheet" href="/layui/css/layui.css">
    <!--
        其他样式的ztree
        <link rel="stylesheet" type="text/css" href="/ztree/css/zTreeStyle/zTreeStyle.css">
        <link rel="stylesheet" href="/ztree/css/awesomeStyle/awesome.css"/>
    -->
    <link rel="stylesheet" href="/ztree/css/metroStyle/metroStyle.css"/>
    <script type="text/javascript" src="/ztree/js/jquery.ztree.all.min.js"></script>
    <script src="/Vue/vue-2.6.12.js"></script>
    <style>
        *{
            margin: 0;
            padding: 0;
        }
        .box{
            width: 100%;
            height: 1700px;
        }
        .list{
            width: 1650px;
            height: 50px;
            margin-left: 20px;
            background-color:rgb(243,243,243);
        }
        .list-left{
            width: 100px;
            height: 30px;
            margin-top: 10px;
            float: left;
        }
        .list-left-left{
            width: 10px;
            height: 30px;
            float: left;
            background: green;
        }
        .list-left-right{
            width: 80px;
            height: 30px;
            font-size: 14px;
            line-height: 30px;
            float: left;
            text-indent: 5px;
        }
        .list-right{
            float: right;
            margin-top: 5px;
            margin-right: 15px;
        }
        .query{
            width: 1650px;
            height: 100px;
            margin-top: 20px;
        }
        .layui-col-md11{
            width: 100%;
        }
        .layui-card-header{
            margin-left: 20px;
            width: 1620px;
            background-color:rgb(243,243,243);
        }
        .query-top-right{
            float: right;
        }
        .layui-form-label{
            margin-left: 20px;
            width:150px;
        }
        .layui-form-item .layui-input-inline {
            float: left;
            width: 220px;
        }
        .record{
            width: 1650px;
            height: 1500px;
            margin-top: 40px;
            margin-left: 20px;
            background-color:rgb(243,243,243);
        }
        .import{
            margin-left: 650px;
        }
        #button_ids{
            display: none;
        }
        .record-right{
            width: 1350px;
            height: 700px;
            margin-left: 15px;
            float: left;
        }
        .layui-table-cell>a{
            color:green;
        }
        .box-btngroup{
            height: 30px;
            margin: 10px 0 10px 0;
        }
        .box-btngroup span{
            color: red;
        }
        .layui-table-cell {
            line-height: 47px;
            height: inherit;
        }
        .layui-table-cell>a{
            color:green;
        }
        .layui-form-item span button{
            margin-left: 150px;
        }

        .layui-card-body{
            height: 50px;
            width: 1620px;
            margin-top: 20px;
        }
    </style>
</head>
<body>
<div id="app" class="box">
    <!--课程审核-->
    <div class="list">
        <div class="list-left">
            <div class="list-left-left"></div>
            <p class="list-left-right">课程审核</p>
        </div>
        <div class="list-right">
            <div class="list-right-left layui-btn layui-icon layui-icon-refresh" onclick="refresh()">&nbsp;刷新</div>
            <div class="list-right-right layui-btn layui-icon layui-icon-left" id="goBack">&nbsp;返回</div>
        </div>
    </div>
    <!--状态搜索-->
    <div class="box-btngroup" style="margin-left: 30px">
        <div class="layui-row buttonBox">
            <!--<button type="button" class="layui-btn " id="courseAuditCounts">全部课程(<span id="courseAuditCount"></span>)</button>
            <button type="button" class="layui-btn " id="courseGroundings">已上架(<span id="courseGrounding"></span>)</button>
            <button type="button" class="layui-btn " id="courseNotGroundings">未上架(<span id="courseNotGrounding"></span>)</button>-->
            <button type="button" class="layui-btn layui-btn-primary" id="approveds">审核通过(<span id="approved"></span>)</button>
            <button type="button" class="layui-btn layui-btn-primary" id="courseAudits">待审核(<span id="courseAudit"></span>)</button>
            <button type="button" class="layui-btn layui-btn-primary" id="fails">未通过(<span id="fail"></span>)</button>
        </div>
    </div>
    <!--筛选查询-->
    <div class="layui-row query">
        <div class="layui-col-md11">
            <div class="layui-card headerCenter">
                <div class="layui-card-header backColor">
                    <i class="layui-icon">&#xe615;</i>
                    筛选查询
                    <div class="query-top-right layui-btn" onclick="retrieval()">高级检索</div>
                </div>
                <div class="layui-card-body">
                    <form class="layui-form">
                        <div class="layui-form-item">
                            <label class="layui-form-label" >输入搜索：</label>
                            <div class="layui-input-inline">
                                <input type="text" name="courseName" id="courseName" required lay-verify="required" placeholder="请输入课程名称" autocomplete="off" class="layui-input">
                            </div>

                            <label class="layui-form-label">课程分类：</label>
                            <div class="layui-input-inline">
                                <select class="layui-select" name="name" id="name">
                                    <option value=""></option>
                                </select>
                            </div>

                            <label class="layui-form-label">上传人员：</label>
                            <div class="layui-input-inline">
                                <input type="text" name="trueName" required lay-verify="required" autocomplete="off" class="layui-input" placeholder="请输入上传人名">
                            </div>
                            <input type="hidden" name="ProductRetrieval" id="ProductRetrieval"/>
                            <div style="float: right;margin-right: -20px;">
                                <button type="button" id="search" class="layui-btn">
                                    <i class="layui-icon layui-icon-search" ></i> 搜索
                                </button>
                                <button type="reset" class="layui-btn layui-btn-warm">
                                    <i class="layui-icon layui-icon-refresh"></i> 重置
                                </button>
                            </div>
                        </div>
                    </form>
                </div>
            </div>
        </div>
    </div>
    <!--数据列表-->
    <div class="record">
        <div class="record-right">
            <!--表-->
            <table id="demoTable" lay-filter="demoTable"></table>
        </div>
    </div>
    <!--表头样式-->
    <div id="button_ids">
        <i class="layui-icon layui-icon-align-left"></i> 课程审核列表
    </div>
    <!--表内操作-->
    <div id="button_caozuo" style="display:none" >
        <a alt="查看" title="查看" href="javascript:;" id="examine" lay-event="selectTable">查看</a>
        <a alt="审核" title="审核" href="javascript:;" id="check" lay-event="check">审核</a>
    </div>
    <!-- 返回 -->
    <p id="title" style="display: none;">课程审核列表</p>
</div>
    <script>
        layui.use(['jquery','layer','table','form'],function(){
            var $=layui.jquery;
            var layer=layui.layer;
            var table=layui.table;
            var form=layui.form;

            //刷新
            refresh = function refresh(){
                location.reload();
            }
            //返回
            $('#goBack').click(function () {
                var title = $('#title').text();
                var iframe = parent.$('.iframe');
                $.each(iframe,function (i,item) {
                    if(title == $(item).attr('_href')){
                        parent.$('#beforeHref').val($(item).attr('_href'));
                        parent.beforeHref();
                        return;
                    }
                });
            });

            //状态按钮切换效果
            $('.buttonBox').children('.layui-btn').click(function () {
                $(this).removeClass('layui-btn-primary').siblings().addClass('layui-btn-primary');
            });

            //表格 所有数据
            getTable();
            function getTable(){
                $.ajax({
                    url:"/course/getCourseTable",
                    type:"post",
                    dataType:"json",
                    success:function (data) {
                        demoTable(data.data);
                    }
                })
            }
            /*表格的渲染*/
            function demoTable(data){
                table.render({
                    elem:'#demoTable',
                    title:"课程审核",
                    data: data,
                    toolbar:'#button_ids',
                    limit:10,
                    width:1620,
                    page:{
                        layout:['count','prev','page','next','limit','skip','refresh'],
                        limits:[10,20,30],
                        first:"首页",
                        last:"尾页",
                    },
                    cols:[[
                        {type:'checkbox'},
                        {field:"",title:"序号",align:'center',width:60,templet:function(data){
                                return data.LAY_INDEX;
                            }},
                        {field:"id",title:"课程编号",align:'center',width:142},
                        {field:"url",title:"课程图片",align:'center',width:150,style: "height:116px;",templet:function(data){
                                return '<img src="'+data.url+'"/>';
                            }},
                        {field:"courseName",title:"课程名称",align:'center',width:150},
                        {field:"trueName",title:"上传人",align:'center',width:150},
                        {field:"courseNprice",title:"现价",align:'center',width:150,templet:function(data){
                                return '现价：' + data.courseNprice;
                            }},
                        {field:"coursePrice",title:"原价",align:'center',width:150,templet:function(data){
                                if(data.coursePrice==null){
                                    return '原价：'+data.courseNprice;
                                }
                                return '原价：' + data.coursePrice;
                            }},
                        {field:"courseStatus",title:"状态",align:'center',width:150,templet:function(data){
                                if(data.courseStatus==2){
                                    return '<input type=\"checkbox\" value="'+data.courseId+'" lay-skin=\"switch\" lay-text=\"上架|下架"\ checked lay-filter="switchTest">';
                                }else if(data.courseStatus==3){
                                    return '<input type=\"checkbox\" value="'+data.courseId+'" lay-skin=\"switch\" lay-text=\"上架|下架" lay-filter="switchTest"\>';
                                }else if(data.courseStatus==4){
                                    return '<p>已删除</p>';
                                }
                            }},
                        {field:"name",title:"课程分类",align:'center',width:150},
                        {field:"result",title:"审核状态",align:'center',width:150,templet:function(data){
                                var result;
                                if(data.result == 1){
                                    result = "审核通过";
                                }else if(data.result == 2){
                                    result = "待审核";
                                }else if(data.courseCstatus == 3){
                                    result = "审核失败";
                                }
                                return '<p>'+result+'</p>';
                            }},
                        {field:'',title:"操作",align:'center',width:148,templet:function(data){
                                if(data.result == 1 || data.result == 3 ){
                                    return '<a alt="查看" title="查看" href="javascript:;" style="margin-right: 10px" lay-event="selectTable">查看</a>' + '<p></p>';
                                }else if(data.result == 2){
                                    return '<a alt="查看" title="查看" href="javascript:;"  style="margin-right: 10px" lay-event="selectTable">查看</a>' +
                                        '<a alt="审核" title="审核" href="javascript:;" lay-event="check">审核</a>';
                                }

                            }}
                    ]]

                })

            }

            //监听课程的上下架状态并修改状态
            form.on('switch(switchTest)', function(data){
                if(data.elem.checked==true){
                    $.ajax({
                        url:"/course/updateCourseStatus",
                        type:"post",
                        dataType:"json",
                        data:{'courseStatus':2,'courseId':data.value},
                        success:function (data) {
                            getTable();
                            layer.msg("修改成功");
                        }
                    })
                }else{
                    $.ajax({
                        url:"/course/updateCourseStatus",
                        type:"post",
                        dataType:"json",
                        data:{'courseStatus':3,'courseId':data.value},
                        success:function (data) {
                            getTable();
                            layer.msg("修改成功");
                        }
                    })
                }
            })
            //给按钮 全部商品赋值
            $.ajax({
                url: '/course/getCourseCounts',
                dataType: 'json',
                type: 'post',
                success: function (data) {
                    $("#courseAuditCount").html(data.data);
                }
            });
            //给已上架的课程赋值
            $.ajax({
                url: '/course/getCourseStatus',
                dataType: 'json',
                type: 'post',
                data: {"courseStatus": 2},
                success: function (data) {
                    $("#courseGrounding").html(data.data);
                }
            });
            //给已上架的课程赋值
            $.ajax({
                url: '/course/getCourseStatus',
                dataType: 'json',
                type: 'post',
                data: {"courseStatus": 3},
                success: function (data) {
                    $("#courseNotGrounding").html(data.data);
                }
            });
            //给审核通过的赋值
            $.ajax({
                url: '/course/getCourseCstatus',
                dataType: 'json',
                type: 'post',
                data: {"result": 1},
                success: function (data) {
                    $("#approved").html(data.data);
                }
            });
            //给待审核赋值
            $.ajax({
                url: '/course/getCourseCstatus',
                dataType: 'json',
                type: 'post',
                data: {"result": 2},
                success: function (data) {
                    $("#courseAudit").html(data.data);
                }
            });
            //给审核不通过赋值
            $.ajax({
                url: '/course/getCourseCstatus',
                dataType: 'json',
                type: 'post',
                data: {"result": 3},
                success: function (data) {
                    $("#fail").html(data.data);
                }
            });

            //根据课程不同的状态渲染表
            //点击全部商品时
            $('#courseAuditCounts').click(function () {
                getTable();
            });

            //点击上架时
            $('#courseGroundings').click(function () {
                getCourseTableByStatus(2);
            });
            //点击未上架时
            $('#courseNotGroundings').click(function () {
                getCourseTableByStatus(3);
            });
            //点击审核通过时
            $('#approveds').click(function () {
                getCourseTableByCstatus(1);
            });
            //点击待审核
            $('#courseAudits').click(function () {
                getCourseTableByCstatus(2);
            });
            //点击未通过
            $('#fails').click(function () {
                getCourseTableByCstatus(3);
            });
            //根据不同的上架状态
            function getCourseTableByStatus(courseStatus){
                var products = {
                    courseStatus: courseStatus,
                }
                $.ajax({
                    url: '/course/getCourseTableByStatus',
                    data: products,
                    dataType: 'json',
                    type: 'post',
                    success: function (data) {
                        demoTable(data.data);
                    }
                });
            };

            //根据不同的审核状态
            function getCourseTableByCstatus(courseCstatus){
                var products = {
                    courseCstatus: courseCstatus,
                }
                $.ajax({
                    url: '/course/getCourseTableByCstatus',
                    data: products,
                    dataType: 'json',
                    type: 'post',
                    success: function (data) {
                        demoTable(data.data);
                    }
                });
            }

            //查询所有课程分类 给下拉框赋值
            $.ajax({
                url: '/course/getCourseClassAll',
                dataType: 'json',
                type: 'post',
                success: function (data) {
                    var syProductCategroys = data.data;
                    for (var i = 0; i < syProductCategroys.length; i++) {
                        $('#name').append('<option value="' + syProductCategroys[i].name + '" >' + syProductCategroys[i].name + '</option>')
                    }
                    form.render('select');//渲染到select标签
                }
            });


            //模糊查
            //课程的模糊查询
            getTableSearch = function getTableSearch(courseName,name,trueName){
                $.ajax({
                    url:"/course/getCourseExamineSearch",
                    type:"post",
                    dataType:"json",
                    data:{'courseName':courseName,'name': name,'trueName':trueName},
                    success:function (data) {
                        demoTable(data.data);
                    }
                })
            };

            //搜索
            $("#search").click(function () {
                var courseName = $("input[name=courseName]").val();
                var name = $("#name").val();
                var trueName = $("input[name=trueName]").val();
                getTableSearch(courseName,name,trueName);
            })

            //高级检索
            retrieval = function retrieval(){
                layer.open({
                    type : 2,
                    title : "高级检索",
                    area : [ '900px', '550px' ],
                    shade : 0,
                    offset: 'auto',
                    content :"/curriculum/courselist/course-sample.html",
                    btn:["确认","取消"],
                    yes:function(index,layero){
                        var child = layero.find('iframe').contents();
                        var courseId = child.find("input[name=courseId]").val();
                        var courseNprice = child.find("input[name=courseNprice]").val();
                        var name = child.find("#name option:selected").val();
                        var courseName = child.find("input[name=courseName]").val();
                        var coursePrimary = child.find("input[name=coursePrimary]").val();
                        var trueName = child.find("input[name=trueName]").val();
                        var param = {
                            'courseId': courseId,
                            'courseNprice': courseNprice,
                            'name': name,
                            'courseName': courseName,
                            'coursePrimary' : coursePrimary,
                            'trueName': trueName
                        }
                        $.ajax({
                            url:"/course/getCourseRetrieval",
                            data:param,
                            type:"post",
                            dataType:"json",
                            success:function (data) {
                                if(data!=null){
                                    demoTable(data.data);
                                }
                                layer.close(index);
                            }
                        })
                    },

                    /*end:function(){
                        //获取数据
                        var data = $("#ProductRetrieval").data("Productdata");
                        if(data!=null){
                            demoTable(data);
                        }
                    }*/
                })
            }

            var createTime = "";
            var updateDate = "";
            //现在时间
            function getTime(){
                var date=new Date();
                var year=date.getFullYear();
                var month=date.getMonth()+1;
                var day=date.getDate();
                var hour=date.getHours();
                var minute=date.getMinutes();
                var second=date.getSeconds();
                var dateStr = year+"-"+zeroFilling(month)+"-"+zeroFilling(day)+" "+zeroFilling(hour)+":"+zeroFilling(minute)+":"+zeroFilling(second);
                updateDate = dateStr;
                createTime = dateStr;
            }
            function zeroFilling(data){
                if(data<10){
                    data="0"+data;
                }
                return data;
            }
            //行内工具栏事件
            table.on('tool(demoTable)',function (obj) {
                localStorage.setItem("courseData",JSON.stringify(obj.data));
                if(obj.event == 'selectTable'){
                    var dictValue = "查看";
                    getTime();
                    var editar = {
                        'logType':2,
                        "type":5,
                        "userId":obj.data.createId,
                        'createDate':createTime,
                        'remark':'查看反馈统计',
                    }
                    $.ajax({
                        url:"/JsLog/addProductJsLog",
                        data:editar,
                        type:'post',
                        dataType:'text',
                        success:function (data) {
                        }
                    });
                    layer.open({
                        type:2,
                        title:"查看",
                        area:["95%","99%"],
                        offset:'auto',
                        btn:["确定","取消"],
                        content:"/curriculum/courselist/course-list-tool-select.html",
                        success:function(layero,index){
                            var child = layero.find('iframe').contents();
                            child.find("#courseName").text(obj.data.courseName);
                            child.find("#createDate").text(obj.data.createDate);
                            child.find("#trueName").text(obj.data.trueName);
                            child.find("#courseNprice").text(obj.data.courseNprice);
                            child.find("#coursePrimary").text(obj.data.coursePrimary);
                            child.find("#className").text(obj.data.name);
                            if(obj.data.likeNum==null){
                                child.find("#likeNum").text(0);
                            }else{
                                child.find("#likeNum").text(obj.data.likeNum);
                            }
                            if(obj.data.collectNum==null){
                                child.find("#collectNum").text(0);
                            }else{
                                child.find("#collectNum").text(obj.data.collectNum);
                            }
                            child.find("#courseInfo").text(obj.data.courseInfo);
                            child.find("#courseIntro").text(obj.data.courseIntro);
                            child.find("#url").attr("src",obj.data.url);
                            child.find("#video").attr("src",obj.data.courseUrl);

                        },
                        yes:function( index,layero){
                            layer.close(index);
                        },
                        btn2:function(index,layero){
                            layer.close(index);
                        },
                        end:function (layero, index) {
                            layer.close(index);
                        }
                    });
                }else if(obj.event == 'check'){
                    layer.open({
                        type:2,
                        title:'审核课程',
                        content:'/examine/curriculumExamine/course-audit.html',
                        area:['752px','550px'],
                        offset:'t',
                        shade:0.4,
                        success:function(layero,index) {
                            var childHtml = layero.find('iframe').contents();
                            childHtml.find('#courseName').text('商品名称：' + obj.data.courseName);
                            childHtml.find('#courseId').val(obj.data.courseId);
                        },
                        end: function () {
                            getTable();
                        }
                    });
                }


            });

        });



    </script>
</body>
</html>